﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace PassportsModel
{
    [DataContract]
    public class PassportRequest
    {
        private string _RequestTaskId;
        [DataMember]
        public PersonDetails PersonDetails { get; set; }
        [DataMember]
        public string AustralianBirthRegistrationCertificateNumber { get; set; }
        [DataMember]
        public string AustralianBirthRegistrationCertificateStateOfIssue { get; set; }
        [DataMember]
        public string AustralianBirthRegistrationCertificateFamilyName { get; set; }
        [DataMember]
        public string AustralianBirthRegistrationCertificateGivenName { get; set; }
        [DataMember]
        public DateTime AustralianBirthRegistrationCertificateDateOfRegistrationOfBirth { get; set; }
        [DataMember]
        public DateTime AustralianBirthRegistrationCertificateDateOfIssueOfCertificate { get; set; }
        [DataMember]
        public SupportingDocumentsRequest BornOnOrAfter20081986SupportingDocuments { get; set; }
        [DataMember]
        public string AustralianCitizenshipCertificateNumber { get; set; }
        [DataMember]
        public DateTime AustralianCitizenshipCertificateDateOfIssue { get; set; }
        [DataMember]
        public string AustralianCitizenshipCertificateFamilyName { get; set; }
        [DataMember]
        public string AustralianCitizenshipCertificatGivenNames { get; set; }
        [DataMember]
        public bool HasNameChanged { get; set; }
        [DataMember]
        public NameChangedRequest NameChangedRequest { get; set; }
        [DataMember]
        public string SecurityQuestion { get; set; }
        [DataMember]
        public string SecurityQuestionAnswer { get; set; }
        [DataMember]
        public ePassportType PassportType { get; set; }
        [DataMember]
        public ePassportTravellerType PassportTravellerType { get; set; }
        [DataMember]
        public EmergencyContactDetails EmergencyContactDetails;
        [DataMember]
        public PreviousPassportDetails PreviousPassportDetails { get; set; }
        [DataMember]
        public Guarantor Guarantor { get; set; }

        public PassportRequest(eGender applicantGender, eGender guarantorGender)
        {
            // TODO how to get a real random?
            _RequestTaskId = GetRandom(1, 1, 50000).ToString();
            this.PersonDetails = new PersonDetails(applicantGender);
            this.EmergencyContactDetails = new EmergencyContactDetails();
            this.PreviousPassportDetails = new PreviousPassportDetails();
            this.NameChangedRequest = new NameChangedRequest();
            this.BornOnOrAfter20081986SupportingDocuments = new SupportingDocumentsRequest();
            this.Guarantor = new Guarantor(guarantorGender);
            this.PassportType = ePassportType.Adult;
            this.PassportTravellerType = ePassportTravellerType.Ordinary;
        }

        public PassportRequest()
        {
            // TODO how to get a real random?
            _RequestTaskId = GetRandom(1, 1, 50000).ToString();
            this.PersonDetails = new PersonDetails(eGender.Female);
            this.EmergencyContactDetails = new EmergencyContactDetails();
            this.PreviousPassportDetails = new PreviousPassportDetails();
            this.NameChangedRequest = new NameChangedRequest();
            this.BornOnOrAfter20081986SupportingDocuments = new SupportingDocumentsRequest();
            this.Guarantor = new Guarantor(eGender.Female);
            this.PassportType = ePassportType.Adult;
            this.PassportTravellerType = ePassportTravellerType.Ordinary;
        }

        public static PassportRequest PassportRequestFactory(eGender applicantGender, eGender guarantorGender)
        {
            PassportRequest passportRequest = new PassportRequest(applicantGender, guarantorGender);

            return (passportRequest);
        }

        static int GetRandom(int seed, int lower, int upper)
        {
            Random randObj = new Random(seed);

            int random = randObj.Next(lower, upper);

            return (random);
        }


        public string RequestTaskId
        {
            get { return _RequestTaskId; }
        }

    }
}